package com.fruit.utils;

import java.util.ArrayList;
import java.util.List;

import com.fruit.service.IGoodsService;
import com.fruit.web.bo.impl.Goods;
import com.fruit.web.constant.SpringBeanConstants;

public final class GoodsUtil {
	
	private static final String HQL = "from Goods where 1=1 ";
	
	public GoodsUtil() {
		
	}

	public static List<Goods> getGoods(String primaryCategoryCode,String what) {
		List<Goods> result = new ArrayList<Goods>();
		String hql = HQL;
		List paraList = new ArrayList();
		if (null == primaryCategoryCode || "".equals(primaryCategoryCode) || null == what || "".equals(what)) {
			return result;
		}
		hql = hql + " and primaryCategoryCode = ? " + " and sfield10 like ? ";
		paraList.add(primaryCategoryCode);
		paraList.add(what);
		Object[] tempValues = null;
		if (paraList.size() > 0) {
			tempValues = new Object[paraList.size()];
			for (int i = 0; i< tempValues.length;i++) {
				tempValues[i] = paraList.get(i);
			}
		}
		IGoodsService<Goods,Long> goodsService = (IGoodsService<Goods,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.GOODS_SERVICE_BEAN_NAME);
		goodsService.setEntityClass(Goods.class);
		goodsService.setPKClass(Long.class);
		result = goodsService.find(hql, tempValues);
		return result;
	}
}
